module OperatorRecorder

  extend ActiveSupport::Concern

  included do |base|
    base.send :before_create, :set_creator
    base.send :before_save, :set_updater
  end


  module ClassMethods

    # def regenerate_all_serial_number
    #   ALIAS_COLUMN.each do |column_name|
    #     if self.attribute_names.include?(column_name)
    #       self.update_all(column_name.to_sym => nil)
    #       self.all.order('created_at asc').each do |obj|
    #         obj.generate_serial_number
    #         obj.save
    #       end
    #       break
    #     end
    #   end
    # end

  end

  def create_info
    [self.creator.name, self.created_at.label].join(" / ") rescue "创建人信息出错"
  end

  def update_info
    [self.updater.name, self.updated_at.label].join(" / ") rescue "更新人信息出错"
  end

  def set_creator
    self.created_by = Session.current_user_id if self.respond_to?(:created_by) && Session.current_user_id
  end

  def set_updater
    self.updated_by = Session.current_user_id if self.respond_to?(:updated_by) && Session.current_user_id
  end


end
